package com.aat.dxfy.javassist.test01;

import javassist.*;

public class Test01 {

	public static void main(String[] args) throws Exception {
		ClassPool pool = ClassPool.getDefault();
		CtClass cc = pool.get("com.aat.dxfy.javassist.test01.Test01");
		CtMethod test = cc.getDeclaredMethod("test");
		if (!test.isEmpty())
			System.out.println("test() is already defined in sample.Test.");
		Class<?> cls=cc.toClass();
		Test01 t= (Test01) cls.newInstance();
		t.test();
		//
		CtMethod demo = cc.getDeclaredMethod("demo");
		CtMethod haha = CtNewMethod.copy(demo, "test", cc, null);
		cc.addMethod(haha);
		cc.writeFile(); 
		// update the class file
		System.out.println("demo() was added.");
	}

	public void test() {
		System.out.println("test mm");
	}
}
